# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=contour
pkgver=0.5.1.7247
pkgrel=1
pkgdesc="Modern C++ Terminal Emulator"
url="https://contour-terminal.org"
arch="x86_64 " # aarch64 fails due to QOpenGLFunctions_3_3_Core, rest lack libunicode
license="Apache-2.0"
makedepends="
	boxed-cpp-dev
	catch2-3
	cmake
	extra-cmake-modules
	fmt-dev
	harfbuzz-dev
	libunicode-dev
	libutempter-dev
	libxcb-dev
	msgsl
	ncurses
	ninja
	qt6-qt5compat-dev
	qt6-qtbase-dev
	qt6-qtdeclarative-dev
	qt6-qtmultimedia-dev
	range-v3-dev
	yaml-cpp-dev
"
subpackages="
	$pkgname-doc
	$pkgname-bash-plugin:_bash:noarch
	$pkgname-fish-plugin:_fish:noarch
	$pkgname-zsh-plugin:_zsh:noarch
"
source="$pkgname-$pkgver.tar.gz::https://github.com/contour-terminal/contour/archive/refs/tags/v$pkgver.tar.gz"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCONTOUR_QT_VERSION=6 \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCONTOUR_INSTALL_TOOLS=ON \
		-DCONTOUR_TESTING=ON \
		-DCRISPY_TESTING=ON \
		-DLIBTERMINAL_TESTING=ON
	cmake --build build
}

check() {
	ctest --test-dir build -C Release --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	rm "$pkgdir"/usr/share/contour/README.md "$pkgdir"/usr/share/contour/shell-integration/shell-integration.tcsh

	mkdir -p "$pkgdir"/usr/share/licenses/"$pkgname"
	mv "$pkgdir"/usr/share/contour/LICENSE.txt "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

_bash() {
	pkgdesc="$pkgdesc (bash integration)"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel bash"

	mkdir -p "$subpkgdir"/usr/share/bash/plugins/"$pkgname"
	mv "$pkgdir"/usr/share/contour/shell-integration/shell-integration.bash "$subpkgdir"/usr/share/bash/plugins/"$pkgname"/contour.plugin.bash
}

_fish() {
	pkgdesc="$pkgdesc (fish integration)"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel fish"

	mkdir -p "$subpkgdir"/usr/share/fish/plugins/"$pkgname"
	mv "$pkgdir"/usr/share/contour/shell-integration/shell-integration.fish "$subpkgdir"/usr/share/fish/plugins/"$pkgname"/contour.plugin.fish
}

_zsh() {
	pkgdesc="$pkgdesc (zsh integration)"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel zsh"

	mkdir -p "$subpkgdir"/usr/share/zsh/plugins/"$pkgname"
	mv "$pkgdir"/usr/share/contour/shell-integration/shell-integration.zsh "$subpkgdir"/usr/share/zsh/plugins/"$pkgname"/contour.plugin.zsh
}

sha512sums="
0c763e543b5a279bb1b9cc1be95607354e817ba8f166aff9554c9157be7959d60e635406fce3d8ba2e15be9a62d46335ead2a497a0dcc3301249f16b317c5b69  contour-0.5.1.7247.tar.gz
"
